home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d23
/
check_os.arc
/
CHECK-OS.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1988-03-06
|
4KB
|
128 lines
program CheckOS;
{ This program was written to be compiled with Turbo Pascal version 4.0. It }
{ checks the Filesize, File Date/Time (last updated), and Checksum of }
{ COMMAND.COM, AUTOEXEC.BAT, and CONFIG.SYS. It was developed to verify }
{ that no virus had installed itself in DOS. It does not stay resident to }
{ guard against Viruses, it just checks the specified drive once when the }
{ program is invoked. It also doesn't have terribly extensive error }
{ checking so little things like the disk being too full to create the }
{ Control file, or a Write protect error will cause a runtime error. I }
{ didn't feel it was necessary to fix these since I only use the program on }
{ my hard disk. }
{ }
{ No warranty is given with this software - use at your own risk. }
{ }
{ R.J. Bartlett 05 March 1988 GEnie address R.BARTLETT }
{$R-,S-,I+,D+,T-,F-,V-,B-,N-,L+}
{$M 8192,0,0}
uses
dos, crt;
type
frec = record fsize, ftime : longint; fchksum : word; end;
const
FileName : array[1..3] of string[20] = (':\COMMAND.COM',
':\CONFIG.SYS',
':\AUTOEXEC.BAT');
var
parm : string[80];
NewRec : array[1..3] of frec;
CtlRec : array[1..3] of frec;
CtlFile : file of frec;
I : integer;
Buffer : array[1..4096] of byte;
ErrFlag : boolean;
Drive : char;
function ChkSumBlock(Count, OldChkSum : word) : word;
var
I, ChkSum : word;
begin
ChkSum := OldChksum;
for I := 1 to count do ChkSum := ChkSum + (Buffer[I] xor I);
ChkSumBlock := ChkSum;
end;
procedure ChkFile(Ndx : word);
var
f : file;
cnt : word;
begin
assign(f, Drive + FileName[Ndx]);
reset(f,1);
NewRec[Ndx].fsize := filesize(f);
getftime(f, NewRec[Ndx].ftime);
NewRec[Ndx].fchksum := 0;
repeat
blockread(f, Buffer, 4096, cnt);
NewRec[I].fchksum := chksumblock(cnt, NewRec[I].fchksum);
until (cnt < 1024);
close(f);
end;
procedure WrtError(ErrMsg : string; fnum : word);
begin
writeln(ErrMsg,' mismatch on file ', Drive, FileName[fnum]);
ErrFlag := true;
end;
procedure ValidateFiles;
var
I : integer;
ch : char;
begin
ErrFlag := false;
for I := 1 to 3 do
begin
read(CtlFile, CtlRec[I]);
if CtlRec[I].fsize <> NewRec[I].fsize then WrtError('File size',I);
if CtlRec[I].ftime <> NewRec[I].ftime then WrtError('Date/Time',I);
if CtlRec[I].fchksum <> NewRec[I].fchksum then WrtError('Checksum ',I);
end;
if ErrFlag then
begin
writeln;
writeln('Check-OS has determined that the file (or files) listed above');
writeln('have been changed since the last time Check-OS was run.');
writeln(#7);
writeln('Do you wish to update the Check-OS control file (\Check-OS.CTL)');
write('to reflect new values (Y or N)? ');
ch := readkey;
writeln(ch);
if upcase(ch) = 'Y' then
begin
rewrite(CtlFile);
for I := 1 to 3 do write(CtlFile, NewRec[I]);
end;
end else writeln('Check-OS found no errors');
end;
begin
assign(output,''); { this allows redirection even though CRT unit is used }
rewrite(output);
writeln('Check-OS Version 1.0a 05 March 88'#13#10);
if (ParamCount < 1) then writeln('Usage -> Check-OS drive ')
else
begin
parm := paramstr(1);
Drive := upcase(parm[1]);
for I := 1 to 3 do ChkFile(I);
assign(CtlFile, Drive + ':\CHECK-OS.CTL');
{$I-} reset(CtlFile); {$I+}
if (ioresult = 0) then ValidateFiles
else
begin
rewrite(CtlFile);
for I := 1 to 3 do write(CtlFile, NewRec[I]);
writeln('Control file created');
end;
close(CtlFile);
end;
end.